'''
Created on 17/09/2013

@author: Hugo
'''
import unittest
import os

from DocumentCollection import DocumentCollection
class TestDocumentCollection(unittest.TestCase):
    docCollect = DocumentCollection("")
    testDocument = ""
    def test_set_directory_folder(self):
        self.assertTrue(os.path.isdir(self.docCollect.docFolder), "Debe haber un directorio con el nombre docs,en siguiente ruta: " + self.docCollect.docFolder)
        self.assertFalse(self.docCollect.setDocumentFolder("adjklfajksldfas/"), "No reconoce directorios inexistentes")
    def test_collection_of_documents(self):
        #agregando documentos para la prueba de reconocimiento de extensiones y texto
        open( os.path.abspath(self.docCollect.docFolder +'/notLikelytoBeNamedLikeThis.txt'),'a').close()
        open( os.path.abspath(self.docCollect.docFolder +'/notLikelytoBeNamedLikeThis.other'),'a').close()
        documents = self.docCollect.collectDocuments()
        self.assertTrue( not isinstance(documents, basestring), "No regreso la estructura de lista")
        for document in documents:
            self.assertTrue(document.endswith(".txt"), "Tomo extensiones de archivos que no deberia")
        
    def test_split_text_into_words_and_return_on_array(self):
        with open(os.path.abspath(self.docCollect.docFolder +'/notLikelytoBeNamedLikeThis.txt'), "a") as myfile:
            myfile.write("appended text%&#%#other23234don't$$ok.or.not.")
            myfile.close()
        tokens = self.docCollect.getTokens(os.path.abspath(self.docCollect.docFolder +'/notLikelytoBeNamedLikeThis.txt'))
        os.remove(os.path.abspath(self.docCollect.docFolder +'/notLikelytoBeNamedLikeThis.txt'))
        os.remove(os.path.abspath(self.docCollect.docFolder +'/notLikelytoBeNamedLikeThis.other'))
        self.assertTrue( not isinstance(tokens, basestring), "No regreso la estructura de lista")
        self.assertTrue(len(tokens) == 7, "No esta realizando bien la division en tokens")
    
    def test_text_normalization(self):
        normalizedTokens = self.docCollect.normalizeTokens(["ALGO","don't","and"])
        self.assertTrue(normalizedTokens[0] == "algo", "No transforma a minusculas")
        self.assertTrue(normalizedTokens[1] == "dont", "No remueve puntuaciones")
        self.assertTrue( len(normalizedTokens) == 2 , "No remueve stop words")
        
if __name__ == '__main__':
    unittest.main()